﻿#include <QFile>
#include <QUrl>
#include "CHeader.h"
#include "CSqlOper.h"
#include "CItemDetailDlg.h"

CItemDetailDlg::CItemDetailDlg(QString sItemExecGuid, QString ItemName, QString sPointName, QWidget *parent)
	: m_sItemExecGuid(sItemExecGuid),m_sItemName(ItemName),m_sPointName(sPointName),QDialog(parent)
{
	ui.setupUi(this);
	setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
	setStyleSheetFile();
	m_mapUnit.insert(enIR, A2T("℃"));
	m_mapUnit.insert(enVoice, A2T("db"));
	m_mapUnit.insert(enCO, A2T("ppm"));
	m_mapUnit.insert(enGas, A2T("ppm"));
	m_mapUnit.insert(enPM25, A2T("ug/m3"));
	m_mapUnit.insert(enPM10, A2T("ug/m3"));
	m_mapUnit.insert(enTemp, A2T("℃"));
	m_mapUnit.insert(enHum, A2T("%RH"));
	m_mapUnit.insert(enCamer, A2T(""));
	m_mapUnit.insert(enUltrasonic, A2T(""));
	queryItem();
}

CItemDetailDlg::~CItemDetailDlg()
{}

void CItemDetailDlg::setStyleSheetFile()
{
	//设置对话框标题
	this->setWindowTitle(A2T("传感器巡检项详情"));
	QString sQssPath = ":/qss/styleSheet.css";
	QFile qss(sQssPath);
	qss.open(QFile::ReadOnly);
	this->setStyleSheet(qss.readAll());
}

void CItemDetailDlg::queryItem()
{
	ui.lineEditItemName->setText(m_sItemName);
	ui.lineEditPointName->setText(m_sPointName);
	QVector<QSqlRecord> vecRecord;
	QString sErrMsg = "";
	selectSensorItemExecByItemExecID(m_sItemExecGuid, vecRecord, sErrMsg);
	for (int i = 0; i < vecRecord.size(); i++)
	{
		int nItemType=vecRecord[i].value("ITEM_TYPE_CODE").toInt();
		ui.lineEditItemValue->setText(vecRecord[i].value("SENSOR_DATA").toString()+m_mapUnit[nItemType]);
		ui.lineEditState->setText(vecRecord[i].value("SENSOR_DATA_DESC").toString());
		ui.lineEditHH->setText(vecRecord[i].value("DATA_THRESHOLD_HH").toString() + m_mapUnit[nItemType]);
		ui.lineEditH->setText(vecRecord[i].value("DATA_THRESHOLD_H").toString() + m_mapUnit[nItemType]);
		ui.lineEditLL->setText(vecRecord[i].value("DATA_THRESHOLD_LL").toString() + m_mapUnit[nItemType]);
		ui.lineEditL->setText(vecRecord[i].value("DATA_THRESHOLD_L").toString() + m_mapUnit[nItemType]);
	}
}
